package com.xunqi.mall.controller;

import com.xunqi.mall.service.CategoryService;
import com.xunqi.mall.vo.CategoryVo;
import com.xunqi.mall.vo.ResponseVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @create: 2020-04-23 20:50
 **/
@RestController
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping(value = "/categories")
    public ResponseVo<List<CategoryVo>> list() {

        ResponseVo<List<CategoryVo>> listResponseVo = categoryService.selectAll();

        return listResponseVo;
    }


    @GetMapping(value = "/categories/{id}")
    public ResponseVo selectById(@PathVariable("id") Integer id) {

        Set<Integer> resultSet = new HashSet<>();
        categoryService.findSubCategoryId(id, resultSet);

        return ResponseVo.success(resultSet);
    }

}
